// 检查日期是否有效
const isDateValid = (...val) => !Number.isNaN(new Date(...val).valueOf())
console.log(isDateValid('December 17, 1995 03:24:00')) // true

// 查找日期位于一年中的第几天
const dayOfYear = (date) => Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24)
console.log(dayOfYear(new Date()))

// 计算两个日期的间隔
const dayDif = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000)
console.log(dayDif(new Date('2021-11-3'), new Date('2022-2-1'))) // 90

// 时间格式化
const timeFromDate = date => date.toTimeString().slice(0, 8)
console.log(timeFromDate(new Date(2021, 11, 2, 12, 30, 0))) // 12:30:00
console.log(timeFromDate(new Date()))